package com.yjc.hire.utils;

import com.yjc.hire.exceptions.GraceException;
import com.yjc.hire.grace.result.ResponseStatusEnum;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Component;

@Component
public class RetryComponet {
    @Retryable(
            //抛出IllegalArgumentException这个异常时进行重试
            value = IllegalArgumentException.class,
            //最大重试次数
            maxAttempts = 5,
            backoff = @Backoff(
                    //重试时间
                    delay = 1000L,
                    //间隔，1/2/4/8
                    multiplier = 2
            )
    )
    public boolean sendSmsWithRetry(){
        return true;
    }

    /**
     * 超过重试次数进行兜底直接调用
     * @return
     */
    @Recover
    public boolean recover(){
        GraceException.disPlay(ResponseStatusEnum.SYSTEM_ERROR);
        return false;
    }
}
